<template>
  <div>
    <div class="history" v-if="isShowHistory">
      <div class="top">
        <h4>历史记录</h4>
        <van-icon name="delete-o" @click="clearSearchList" />
      </div>
      <!-- 记录内容区域 -->
      <div class="down">
        <van-tag
          @click="tagClick(i)"
          v-for="(i,index) in historyKeywordList"
          :key="index"
          plain
          type="default"
        >{{i}}</van-tag>
      </div>
    </div>
    <!-- 热门搜索 -->
    <div class="history">
      <div class="top">
        <h4>热门搜索</h4>
        <!-- <van-icon name="delete-o" /> -->
      </div>
      <!-- 记录内容区域 -->
      <div class="down">
        <van-tag
          v-for="(i, index) in hotKeywordList"
          @click="tagClick(i.keyword)"
          :key="index"
          plain
          :type="i.is_hot===1?'danger':'default'"
        >{{i.keyword}}</van-tag>
      </div>
    </div>
  </div>
</template>
<script>
import { clearSearchList } from '../api/search'
export default {
  props: ['historyKeywordList', 'hotKeywordList'],
  data () {
    return {
      isShowHistory: true
    }
  },
  methods: {
    tagClick (i) {
      console.log(i)
      this.$emit('changeTag', i)
    },
    // 清除历史数据
    async clearSearchList () {
      const res = await clearSearchList()
      console.log(res)
      if (res.errno === 0) {
        this.$toast.success('清空成功')
        setTimeout(() => {
          this.isShowHistory = false
        }, 1000)
      }
    }
  },
  created () {
  }
}
</script>

<style lang="less" scoped>
.history {
  padding: 0 2%;
  background-color: #fff;
  margin-bottom: 0.2rem;
  .top {
    display: flex;
    justify-content: space-between;
    height: 0.5rem;
    font-size: 0.2rem;
    align-items: center;
    h4 {
      font-weight: normal;
    }
  }
  .down {
    .van-tag {
      font-size: 0.14rem;
      margin-right: 0.1rem;
      margin-bottom: 0.1rem;
      padding: 0.03rem;
      // color: #949494;
    }
  }
}
</style>
